package previous.Test_0407;

import java.util.Scanner;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
public class Solution {
    //二分查找数组
    public static void main1(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int x=scan.nextInt();
        int[] data=new int[200];
        for(int i=0;i<200;i++) {
            data[i]=4*i+6;
        }
        int left=0;
        int right=199;
        while(left<right) {
            int mid=left+(right-left+1)/2;
            if(data[mid]>x) {
                right=mid-1;
            }else if(data[mid] <x) {
                left=mid+1;
            }else {
                System.out.println(mid);
                return;
            }
        }
        scan.close();
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n=scan.nextInt();
        int[] l=new int[n];
        int[] w=new int[n];
        int[] c=new int[n];
        for(int i=0;i<n;i++) {
            l[i]=scan.nextInt();
            w[i]=scan.nextInt();
            c[i]=scan.nextInt();
        }
        int count=0;
        for(int i=0;i<n-1;i++) {
            for(int j=i+1;j<n;j++) {
                if(l[i]>l[j] && w[i]<w[j] && c[i]!=c[j]) {
                    count++;
                }
            }
        }
        System.out.println(count);
        scan.close();
    }
}
